﻿using System;

namespace AbstractProducts
{
    public sealed class ProductRef : IEquatable<ProductRef>
    {
        private readonly string m_ProductName;

        public ProductRef(string productName)
        {
            m_ProductName = productName;
        }

        public string ProductName
        {
            get { return m_ProductName; }
        }

        public override string ToString()
        {
            return m_ProductName;
        }

        public bool Equals(ProductRef other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return Equals(other.m_ProductName, m_ProductName);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (ProductRef)) return false;
            return Equals((ProductRef) obj);
        }

        public override int GetHashCode()
        {
            return m_ProductName.GetHashCode();
        }

        public static bool operator ==(ProductRef left, ProductRef right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(ProductRef left, ProductRef right)
        {
            return !Equals(left, right);
        }
    }
}
